package edu.tongji.engine.test;

import java.io.File;

public class ReplaceFileName {


	    public static void main(String[] args) {
	        String path = "G:/tmp/";
	        File rootdir = new File(path);
	        File target = null;
	        File toChange = null;
	        String name;
	        String names[] = rootdir.list();
	        for(int i = 0; i < names.length; i++) {
	            name = names[i].replace("tmp", "jpg");
	            target = new File(path+ names[i]);
	            toChange = new File(path + name);
	            int j = 0;
	            if(target.exists() && !toChange.exists()) {
	                target.renameTo(toChange);
	                System.out.print(names[i] + "-->" + name);
	                System.out.println("\t changed: "+ ++j);
	            }else{
	            	System.out.println(names[i]+" isn't exits");
	            	
	            }
	            
	        }
	    }
}

